<%--
  Created by IntelliJ IDEA.
  User: sofwin
  Date: 2021/3/26
  Time: 10:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath()+"/";%>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=path%>">
    <meta charset="utf-8">
    <title>会员添加--layui后台管理模板</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="layui/css/font.css">
    <link rel="stylesheet" href="layui/css/xadmin.css">
    <script type="text/javascript" src="layui/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="layui/js/xadmin.js"></script>
</head>
<body class="childrenBody">
<form class="layui-form" id="form" style="width:80%;">
    <input type="hidden" name="id" value="${user.id}"/>
    <div class="layui-form-item">
        <label class="layui-form-label">登录名</label>
        <div class="layui-input-block">
            <input type="text" name="loginAccount" value="${user.loginAccount}" class="layui-input userName" lay-verify="required" placeholder="请输入登录名">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" name="loginPwd" value="${user.loginPwd}" class="layui-input userEmail" lay-verify="email" placeholder="请输入邮箱">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="realName" value="${user.realName}" class="layui-input userEmail" lay-verify="email" placeholder="请输入邮箱">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属部门</label>
        <div class="layui-input-block">
            <select name="deptId" class="userGrade" lay-filter="userGrade">
                <c:forEach items="${depts}" var="dept">
                    <option value="${dept.id}" <c:if test="${user.deptId==dept.id}">selected</c:if>>${dept.deptName}</option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属角色</label>
        <div class="layui-input-block">
            <select name="roleId" class="userGrade" lay-filter="userGrade">
                <c:forEach items="${roles}" var="dept">
                    <option value="${dept.id}" <c:if test="${user.roleId==dept.id}">selected</c:if>>${dept.roleName}</option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" lay-filter="ofilter" lay-skin="switch" lay-text="开启|关闭" <c:if test="${user.flag==1}">checked</c:if>>
            </div>
            <input type="hidden" id="flag" value="${user.flag}" name="flag"/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" type="button" id="msubmit">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript">
    layui.use(['form','jquery','layer'],function(){
        let form = layui.form;
        layer = layui.layer;
        let $=layui.jquery;
        form.on('switch(ofilter)', function(data){
            console.log(data.elem); //得到checkbox原始DOM对象
            console.log(data.elem.checked); //开关是否开启，true或者false
            console.log(data.value); //开关value值，也可以通过data.elem.value得到
            console.log(data.othis); //得到美化后的DOM对象
            if(data.elem.checked){
                $("#flag").val(1);            }
        });
        form.render();
        $("#msubmit").click(function () {
            var param =$("#form").serialize();
            $.ajax({
                url:'system/user/save',
                type:'post',
                dataType:'json',
                data:param,
                success:function(ret){
                    if(ret.status){
                        layer.msg('操作成功！',function () {
                            // 刷新父页面
                            parent.document.location='system/user/data';
                            // 将当前的弹出层关闭
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index);
                        });


                    }
                }
            });
        });
    })
</script>
</body>
</html>